import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import '../../resources/kq_theme_colors.dart';
import 'package:kq_flutter_core_widget/widgets/button/kq_ink_well.dart';

/// 圆角
class KqCircleView extends StatefulWidget {
  /// icon
  final String? iconUrl;

  /// icon 大小
  final double? iconSize;

  /// 文本
  final String? text;

  /// 文本大小
  final double? fontSize;

  /// 文本颜色
  final Color? color;

  /// 自定义
  final Widget? custom;

  /// 宽
  final double? width;

  /// 高
  final double? height;

  /// 圆角
  final BorderRadiusGeometry? radius;

  /// 圆角值：BorderRadius.all可通过radiusValue快捷设置
  final double? radiusValue;

  /// icon和text之间的间距
  final double? spacing;

  /// 背景色
  final Color? backgroundColor;

  /// 边框颜色
  final Color? borderColor;

  /// padding
  final EdgeInsetsGeometry? padding;

  /// 点击
  final Function()? onTap;

  const KqCircleView(
      {this.iconUrl,
      this.iconSize,
      this.text,
      this.fontSize,
      this.color,
      this.custom,
      this.width,
      this.height,
      this.radius,
      this.radiusValue,
      this.spacing,
      this.backgroundColor,
      this.borderColor,
      this.padding,
      this.onTap,
      super.key})
      : assert((custom != null || (text != null || iconUrl != null)) &&
            (width != null && padding == null ||
                (width == null && padding != null)));

  @override
  State<KqCircleView> createState() => _KqCircleViewState();
}

class _KqCircleViewState extends State<KqCircleView> {
  @override
  Widget build(BuildContext context) {
    return KqInkWell(
        onTap: () => widget.onTap?.call(),
        child: Container(
          height: widget.height ?? 22.r,
          width: widget.width,
          padding: widget.padding,
          decoration: BoxDecoration(
              color: widget.backgroundColor ?? KqThemeColors.bgWhite,
              border: Border(
                  top: BorderSide(
                      width: widget.borderColor != null ? 1.r : 0,
                      color: widget.borderColor ?? KqThemeColors.bgTransparent),
                  left: BorderSide(
                      width: widget.borderColor != null ? 1.r : 0,
                      color: widget.borderColor ?? KqThemeColors.bgTransparent),
                  right: BorderSide(
                      width: widget.borderColor != null ? 1.r : 0,
                      color: widget.borderColor ?? KqThemeColors.bgTransparent),
                  bottom: BorderSide(
                      width: widget.borderColor != null ? 1.r : 0,
                      color:
                          widget.borderColor ?? KqThemeColors.bgTransparent)),
              borderRadius: widget.radius ??
                  BorderRadius.all(Radius.circular(widget.radiusValue ?? 10))),
          child: widget.custom ??
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                mainAxisSize: MainAxisSize.min,
                children: [
                  Visibility(
                      visible: widget.iconUrl != null ? true : false,
                      child: Image.asset(
                        widget.iconUrl ?? '',
                        width: widget.iconSize,
                        height: widget.iconSize,
                        fit: BoxFit.fill,
                      )),
                  Visibility(
                      visible: widget.spacing != null ? true : false,
                      child: SizedBox(
                        width: widget.spacing ?? 4.r,
                      )),
                  Text(
                    widget.text ?? '',
                    style: TextStyle(
                        color: widget.color, fontSize: widget.fontSize),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  )
                ],
              ),
        ));
  }
}
